import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/29 11:40
 * @description 模拟
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int totalSteps(int[] nums) {
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        int step = 0;
        boolean finish = true;
        while (finish) {
            List<Integer> newList = new ArrayList<>();
            Set<Integer> set = new HashSet<>();
            for (int i = 1; i < list.size(); i++) {
                if (list.get(i - 1) > list.get(i)) {
                    set.add(i);
                }
            }
            if (set.isEmpty()) {
                finish = false;
                continue;
            }
            for (int i = 0; i < list.size(); i++) {
                if (!set.contains(i)) {
                    newList.add(list.get(i));
                }
            }
            list = newList;
            step++;
        }
        return step;
    }
}
